package com.isunland.managesystem.adapter;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseButterKnifeAdapter;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.rContractListMain;
import com.isunland.managesystem.utils.MyStringUtil;
import com.isunland.managesystem.utils.MyUtils;
import java.util.ArrayList;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/4/5 15:01
 */

public class CustomerBillAdapter extends BaseButterKnifeAdapter<rContractListMain> {
  @SuppressWarnings("unused")
  public CustomerBillAdapter(BaseVolleyActivity context, ArrayList<rContractListMain> objects) {
    super(context, objects);
  }

  @Override protected int setLayoutId() {
    return R.layout.adapter_new_list;
  }

  @NonNull @Override protected BaseViewHolder initHolder(View convertView) {
    return new ViewHolder(convertView);
  }

  @Override
  protected void initView(rContractListMain item, BaseViewHolder baseHolder, int position) {
    ViewHolder holder = (ViewHolder) baseHolder;

    //noinspection deprecation
    holder.ivLogo.setImageDrawable(TextDrawable.builder()
        .buildRound(MyStringUtil.substring(item.getPartName(), 0, 2),
            context.getResources().getColor(R.color.primary)));

    holder.tvContent1.setText(item.getContractCode());
    holder.tvContent2.setText(item.getContractName());
    holder.tvBottom.setText(MyStringUtil.connect(item.getRespManName(), MyStringUtil.SEPEREATE,
        item.getContractSignDate()));
    MyUtils.switchDataStutus(context, holder.tvIndex, item.getDataStatus());
  }

  protected class ViewHolder extends BaseViewHolder {
    @BindView(R.id.iv_logo) ImageView ivLogo;
    @BindView(R.id.tv_title) TextView tvTitle;
    @BindView(R.id.tv_content1) TextView tvContent1;
    @BindView(R.id.tv_content2) TextView tvContent2;
    @BindView(R.id.tv_content3) TextView tvContent3;
    @BindView(R.id.tv_bottom) TextView tvBottom;
    @BindView(R.id.iv_more) ImageView ivMore;
    @BindView(R.id.tv_index) TextView tvIndex;

    ViewHolder(View view) {
      super(view);
      tvTitle.setVisibility(View.GONE);
      tvContent3.setVisibility(View.GONE);
      ivMore.setVisibility(View.GONE);
    }
  }
}
